import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../app_files.dart';
import 'action.dart';
import 'state.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

Widget buildView(
    StoreDetailViewState state, Dispatch dispatch, ViewService viewService) {


  return  MediaQuery(
    //设置文字大小不随系统设置改变
    data: MediaQuery.of(viewService.context).copyWith(textScaleFactor: 1.0),
    child: Scaffold(
      appBar: myAppBar(viewService.context, title: '服务网点'),
      body: Column(
        children: [
          Container(
            height: 144,
            width: double.infinity,
            child: Swiper(
              itemBuilder: (BuildContext context, int index) {
                StoreDetailModel model = state.models[index];
                return Container(
                  height: 132,
                  padding: EdgeInsets.only(top: 18, left: 15, right: 15),
                  color: Colors.white,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Image.asset('images/ic_store.png'),
                          Padding(
                            padding: EdgeInsets.only(left: 10),
                            child: Text(
                              model.storeName,
                              style: TextThemeConfig.Font15WithColor22,
                            ),
                          ),
                          Expanded(child: Container()),
                          Container(
                            height: 20,
                            width: 50,
                            decoration: BoxDecoration(
                              color: ThemeConfig.mainColor,
                              borderRadius: BorderRadius.all(Radius.circular(2)),
                            ),
                            child: InkWell(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Image.asset('images/ic_call.png'),
                                  Padding(
                                    padding: EdgeInsets.only(left: 5, bottom: 1),
                                    child: Text(
                                      '拨打',
                                      style: TextThemeConfig.Font12WithColorWhite,
                                    ),
                                  ),
                                ],
                              ),
                              onTap: () => dispatch(
                                  StoreDetailViewActionCreator.onCall(
                                      model.phone)),
                            ),
                          )
                        ],
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 15),
                        child: Text(
                          '${model.storeAddress}    ${model.phone}',
                          style: TextThemeConfig.Font13WithColor66,
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 4),
                        child: Text(
                          model.storeTime,
                          style: TextThemeConfig.Font13WithColor66,
                        ),
                      ),
                    ],
                  ),
                );
              },
              itemCount: state.models.length,
              pagination: SwiperPagination(
                builder: DotSwiperPaginationBuilder(
                    activeColor: ThemeConfig.mainColor, color: Colors.black45),
              ),
              autoplay: false,
              autoplayDelay: 5000,
              viewportFraction: 1,
              onIndexChanged: (int index) =>
                  dispatch(StoreDetailViewActionCreator.onIndexChange(index)),
              scale: 1,
            ),
          ),
          Expanded(
            child: AmapView(
              mapType: MapType.Standard,
              showZoomControl: false,
              maskDelay: Duration(milliseconds: 500),
              onMapCreated: (controller) async {
                dispatch(StoreDetailViewActionCreator.addMarker(controller));
              },
            ),
          ),
        ],
      ),
    ),
  );
}
